using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Data.SqlClient;
using System.IO;

namespace BasicFilters.Controllers
{

    [HandleError(Order = 1, ExceptionType = typeof(SqlException),
        View = "DatabaseError")]
    [HandleError(Order = 2, ExceptionType = typeof(IOException),
        View = "FileSystemError")]
    [HandleError(Order = 3)]
    public class ProblematicController : Controller
    {
        public ActionResult ThisThrowsASqlException()
        {
            SqlConnection conn = new SqlConnection(@"Server=.\sqlexpress;initial catalog=nonexistentDb;Integrated Security=SSPI");
            conn.Open();
            return View();
        }

        public ActionResult ThisThrowsAIOException()
        {
            System.IO.File.Open(@"C:\ThisFolderIsMostLikelyNotToExists\File.txt", FileMode.Open);
            return View();
        }

        public ActionResult ThisThrowsAnApplicationException()
        {
            throw new ApplicationException("Never throw such an Exception");
        }

        public ActionResult ThisThrowsASeriesOfExceptions()
        {
            ApplicationException innerOne = new ApplicationException("This is the inner excpetion");
            throw new Exception("This is an Exception", innerOne);
        }
    }
}